<template>
  <el-dialog v-model="isShowAddGoods"
             :before-close="handleClose"
             title="添加线下采购单"
             draggable
             width="60%"
             append-to-body
  >

    <el-form :inline="true" :model="queryParams" label-width="100px">
      <div style="display: flex;flex-wrap: wrap">
        <el-col :span="8">
          <el-form-item label="线下采购单号">
            <el-input v-model="queryParams.purchaseCode" placeholder="线下采购单号" clearable/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item >
            <el-button icon="Search" type="primary" @click="getList">查询</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </div>
    </el-form>

    <vxe-table
        ref="tableRef"
        border
        style="margin-top: 10px;"
        align="center"
        :data="tableList"
        height="300"
        :radio-config="{ trigger:'row'}"
        :row-config="{isCurrent: true, isHover: true}"
    >
      <vxe-column type="radio" width="60"></vxe-column>
      <vxe-column type="seq" width="80" title="序号"  ></vxe-column>
      <vxe-column field="purchaseCode"  width="220" title="线下采购单号"></vxe-column>
      <vxe-column field="vendorName" title="供应商名称"></vxe-column>
      <vxe-column field="warehouseName" title="入库仓库"></vxe-column>
      <vxe-column field="actualPurchaseNum" title="采购数量"></vxe-column>
      <vxe-column field="putawayNum" title="采购入库数量"></vxe-column>
      <vxe-column field="totalMoney" title="采购总额"></vxe-column>
    </vxe-table>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="clickSel"> 确定 </el-button>
          <el-button @click="handleClose">取消</el-button>
        </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {onMounted, ref} from "vue";
import {getReturnList} from "@/api/scApi";

const { proxy } = getCurrentInstance()
let queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
 let tableList=ref([])
const props = defineProps({
  isShowAddGoods: {
    type: Boolean,
    default: false
  },
})

const emits = defineEmits(['cancel'])

function handleClose(){
  emits('cancel')
}

let total = ref(1)
function getList(){
  let params={
    pageNum:queryParams.value.pageNum,
    pageSize:queryParams.value.pageSize,
    param:queryParams.value
  }
  getReturnList(params).then(res=>{
    if(res.code===200){
      tableList.value =res.data
      total.value=res.total
    }
  })
}

onMounted(()=>{
  getList()
})

const resetQuery = () => {
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
  }
  getList();
};

function clickSel(){
  let selRows = proxy.$refs.tableRef.getRadioRecord()
  if(selRows){
    emits('cancel',selRows)
  }else{
    proxy.$modal.msgWarning("请选择一条数据!")
  }
}
</script>

<style scoped lang="scss">

</style>